package com.smxy.mall.service.impl;

import com.smxy.mall.dao.CategoryDao;
import com.smxy.mall.entity.Category;
import com.smxy.mall.model.request.CategoryReq;
import com.smxy.mall.service.CategoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryDao categoryDao;

    @Override
    public List<Category> list(Integer shopId) {
        return categoryDao.findByShopId(shopId);
    }

    @Override
    public Category save(CategoryReq categoryReq) {
        Category category = new Category();
        category.setCategoryName(categoryReq.getCategoryName());
        category.setCategoryIcon(categoryReq.getCategoryIcon());
        category.setShopId(categoryReq.getShopId());
        if(!StringUtils.isEmpty(categoryReq.getId())){
            category.setId(categoryReq.getId());
        }
        return categoryDao.save(category);
    }
}
